<!--
 * @Author: gonghairun
 * @Date: 2020-11-14 16:23:20
 * @LastEditors: zhangyongbing
 * @LastEditTime: 2022-03-15 16:36:33
 * @Description: //描述
-->
<template>
	<div class="box">
		<iframe width="100%" height="100%" :src="pdfUrl" class="pdf-viewer" />
		<!-- </div> -->
	</div>
</template>
<script>
export default {
	name: "pdfPreview",
	data() {
		return {
			pdfUrl: "",
		};
	},
	props: {
		pdfurl: {
			tpye: String,
			default: "",
		},
	},
	mounted() {
		this.getQueryString();
		if (this.$route.query.dataType != 1) {
			// var staticUrl = __static;//打包路径
			var staticUrl = "/static"; //本地路径
			var baseUrl = "/${this.$ServiceName}/api/external/protected/file/down?id=" + this.fileId + "&token=" + this.token;
			this.pdfUrl = staticUrl + "/pdf/web/viewer.html?file=" + this.baseurl + encodeURIComponent(baseUrl);
		} else {
			var staticUrl = "/static"; //本地路径
			this.pdfUrl = staticUrl + "/pdf/web/viewer.html?file=" + encodeURIComponent(this.$route.query.pdfUrl);
		}
	},
	methods: {
		getQueryString() {
			var name, value;
			var str = location.href; //取得整个地址栏
			var num = str.indexOf("?");
			str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]

			var arr = str.split("&"); //各个参数放到数组里
			console.log(arr);
			for (var i = 0; i < arr.length; i++) {
				num = arr[i].indexOf("=");
				if (num > 0) {
					name = arr[i].substring(0, num);
					value = arr[i].substr(num + 1);
					this[name] = value;
				}
			}
		},
	},
};
</script>

<style lang="less" scoped>
.box {
	width: 100%;
	height: calc(100vh) !important;
}
</style>
